package com.example.xxpk.service.purchaserecord;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.xxpk.mapper.PurchaseRecordMapper;
import com.example.xxpk.pojo.PurchaseRecord;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhangguihong
 * @since 2025-02-19
 */
@Service
@RequiredArgsConstructor
public class PurchaseRecordServiceImpl extends ServiceImpl<PurchaseRecordMapper, PurchaseRecord> implements IPurchaseRecordService {

    private final PurchaseRecordMapper purchaseRecordMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean addPurchaseRecord(PurchaseRecord purchaseRecord) {
        // 设置购买时间为当前时间
        purchaseRecord.setPurchaseTime(LocalDateTime.now());
        return purchaseRecordMapper.insert(purchaseRecord) > 0;
    }


}
